<?php

// -+----------------------------+-
// LyApi [ V2.0 ] - 全新开发版本
// 数据库连接器 - Connector
// -+----------------------------+-

namespace LyApi\Support\Database;

use Exception;
use LyApi\Support\Config;
use Medoo\Medoo;

class Connector
{

    private static $conntype = "medoo";

    public function __construct($type = "medoo")
    {
        self::choose($type);
    }

    public function __get($name): Medoo
    {
        $conf = Config::dotConfig("database");
        if (!array_key_exists($name, $conf)) {
            throw new ConnException("[" . strtoupper($name) . "] 数据库连接失败！");
        }

        if (self::$conntype == "medoo") {
            $temp = new Medoo($conf[$name]);
        }

        return $temp;
    }

    public static function choose($type)
    {
        self::$conntype = strtolower($type);
    }

    public static function connect($name): Medoo
    {
        $temp = new self(self::$conntype);
        return $temp->$name;
    }

    public static function mongodb(){
        // MongoDB 相关接入程序
    }

}
